//
//  ListViewBar.swift
//  MovieAppDemo
//
//  Created by yanjin on 2025/2/3.
//

import SwiftUI

struct ListViewBar: View {
    @Environment(\.dismiss) var dismiss
    var bannersdata: [Banner] = banners
    @Binding var showBarInfo: Bool
    @Binding var type: Int
    @Binding var showSearchTags: Bool
    @Binding var tag:String
    @Binding var fav_type: Int
    
    var body: some View {
        ZStack {
            HStack {
                Button {
                    dismiss()
                } label: {
                    Image(systemName: "chevron.left")
                        .font(.system(size: 20))
                        .foregroundStyle(.white)
                }
                .padding(10)

                HStack {
                    if showBarInfo {
                        Image(bannersdata[type].image)
                            .resizable()
                            .scaledToFill()
                            .frame(width: 30, height: 30)
                            .clipShape(Circle())
                            .transition(.move(edge: .bottom).combined(with: .opacity))

                        Text(bannersdata[type].title)
                            .font(.system(size: 20))
                            .transition(.move(edge: .bottom).combined(with: .opacity))
                            .lineLimit(1)
                            .foregroundColor(.white)
                    }
                }

                Spacer()

                if showBarInfo {
                    Button {
                        showSearchTags.toggle()
                    } label: {
                        Text(tag)
                    }
                    .foregroundStyle(.black)
                    .padding(.horizontal, 10)
                    .padding(.vertical, 8)
                    .background(.white)
                    .clipShape(RoundedRectangle(cornerRadius: 5))
                    .transition(.move(edge: .bottom).combined(with: .opacity))
                }

                Menu {
                    Button {
                        // 选择分类
                        showSearchTags.toggle()
                    } label: {
                        Label("选择分类", systemImage: "magnifyingglass")
                    }

                   

                    Button {
                        // 只看推荐
                        fav_type = fav_type == 0 ? 1 : 0
                    } label: {
                        Label(fav_type == 0 ? "只看推荐" : "取消只看推荐", systemImage: "flame")
                    }
                    
                    
                    Button {
                        // 只看推荐
                        fav_type = fav_type == 0 ? 3 : 0
                    } label: {
                        Label(fav_type == 0 ? "只看未看" : "取消只看未看", systemImage: "clock")
                    }
                } label: {
                    Image(systemName: "ellipsis")
                        .font(.system(size: 20))
                        .foregroundStyle(.white)
                        .rotationEffect(.degrees(90))
                        .padding(10)
                }
            }
            .animation(.default, value: showBarInfo)
        }
        .frame(maxWidth: .infinity)
        .padding(.bottom)
        .padding(.horizontal, 10)
        
        
    }
}

#Preview {
    @Previewable @State var showBarInfo: Bool = true
    @Previewable @State var type: Int = 3
    @Previewable @State var showSearchTags: Bool = true
    @Previewable @State var tag:String = "WEBTOON"
    @Previewable @State var fav_type: Int = 0
    ListViewBar(showBarInfo:$showBarInfo,type: $type,showSearchTags: $showSearchTags,tag: $tag,fav_type:$fav_type)
        .background(Color("BgColor1"))
}
